package com.gexiaobao.pigeon.viewmodel

import androidx.databinding.ObservableField
import androidx.lifecycle.ViewModel
import com.gexiaobao.pigeon.app.model.bean.PassResultBody
import java.lang.StringBuilder

/**
 * @Author : hxw
 * @Date : 2024/7/25 11:22
 * @Describe :
 */
class DialogViewModel() : ViewModel() {

    private lateinit var mData: PassResultBody

    var rank = ObservableField<String>()//排名
    var speed = ObservableField<String>()//单关分速
    var raceSpeed = ObservableField<String>()//综合分速
    var raceRank = ObservableField<String>()//综合排名
    var homingTime = ObservableField<String>()//归巢时间
    var totalTime = ObservableField<String>()//飞行时间
    var username = ObservableField<String>()//参赛名
    var ringId = ObservableField<String>()//足环号
    var fosterName = ObservableField<String>()//寄养人
    var memberNum = ObservableField<String>()//棚号
    var distance = ObservableField<String>()//空距
    var lonLat = ObservableField<String>()//归巢经纬度

    fun setData(data: PassResultBody) {
        this.mData = data
        rank.set(mData.rank)
        speed.set(mData.speed)
        raceSpeed.set(mData.raceSpeed)
        raceRank.set(mData.raceRank)
        homingTime.set(mData.homingTime)
        totalTime.set(mData.totalTime)
        username.set(mData.username)
        ringId.set(mData.ringId)
        fosterName.set(mData.fosterName)
        memberNum.set(mData.memberNum)
        distance.set(mData.distance)
        if (mData.lonLat.isNotEmpty()) {
            val result = mData.lonLat.split(" ")
            if (result.isNotEmpty()) {
                val sb = StringBuilder()
                result.forEachIndexed { index, s ->
                    sb.append(s.trim() + if (index == result.size - 1) "" else "\n")
                }

                lonLat.set(sb.toString())
            }
        }
    }

    fun onCloseButtonClick() {
        // 处理关闭按钮点击事件逻辑
        // 可以在这里添加对话框关闭后的处理逻辑
        // 例如：关闭 Dialog
    }

    fun onSureButtonClick() {
        // 处理关闭按钮点击事件逻辑
        // 可以在这里添加对话框关闭后的处理逻辑
        // 例如：关闭 Dialog
    }

}
